<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="借出状态" prop="borrowflag">
        <el-select v-model="queryParams.borrowflag" placeholder="请选择借出状态" clearable >
          <el-option
            v-for="dict in dict.type.borrow_dict"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"/>
        </el-select>
      </el-form-item>
      <el-form-item label="归还状态" prop="returnflag">
        <el-select v-model="queryParams.returnflag" placeholder="请选择归还状态" clearable>
          <el-option
            v-for="dict in dict.type.borrow_still"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"/>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="审批状态" prop="statusflag">-->
<!--        <el-select v-model="queryParams.statusflag" placeholder="请选择审批状态" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.borrow_audit"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="parseInt(dict.value)"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"

        >借阅</el-button>
<!--        v-hasPermi="['system:borrow:add']"-->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"

        >归还</el-button>
<!--        v-hasPermi="['system:borrow:edit']"-->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"

        >删除借阅信息</el-button>
<!--        v-hasPermi="['system:borrow:remove']"-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>
    <!-- 借阅管理表格数据 -->
    <el-table v-loading="loading" :data="borrowList"  @row-click="handleRowClick" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" key = "id"  v-if = "columns[25].visible" />
      <el-table-column label="文件类型" align="center" key= "filetype" prop="filetype"  v-if = "columns[0].visible"  />
      <el-table-column label="案卷题名" align="center"  key= "vname" prop="vname"  v-if = "columns[22].visible" />
      <el-table-column label="文件题名" align="center"  key= "filename" prop="filename" v-if = "columns[15].visible" />
      <el-table-column label="借阅人" align="center" key= "name"prop="name" v-if = "columns[2].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="单位名称" align="center" key= "company" prop="company"  v-if = "columns[3].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="证件号码" align="center" key= "company" prop="paperno" v-if = "columns[4].visible" :show-overflow-tooltip="true" />
      <el-table-column label="联系电话" align="center"  key= "telephone" prop="telephone"  v-if = "columns[5].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="公司地址" align="center" key= "address" prop="address" v-if = "columns[6].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="借出原因" align="center" key= "reason" prop="reason" v-if = "columns[7].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="介绍信" align="center" key= "recommendation" prop="recommendation" v-if = "columns[8].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="借出时间" align="center" key= "borrowtime" prop="borrowtime"  width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.borrowtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借出经办人" align="center" key= "borrowoperator"  prop="borrowoperator" v-if = "columns[9].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="借出期限" align="center"  key= "loantime" prop="loantime" v-if = "columns[10].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="到期时间" align="center"  key= "duetime" prop="duetime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.duetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="归还时间" align="center"  key= "returntime" prop="returntime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returntime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="归还经办人" align="center"  key= "returnoperator" prop="returnoperator" v-if = "columns[11].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="申请时间" align="center"  key= "applytime" prop="applytime" width="180" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applytime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批人" align="center"  key= "approvaloperator" prop="approvaloperator" v-if = "columns[13].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="审批时间" align="center"  key= "approvaltime" prop="approvaltime" width="180" v-if="columns[24].visible" :show-overflow-tooltip="true" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvaltime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工程名称" align="center"  key= "engname" prop="engname" v-if = "columns[14].visible" :show-overflow-tooltip="true"/>

      <el-table-column label="用户id" align="center"  key= "userId" prop="userId" v-if = "columns[16].visible" :show-overflow-tooltip="true"/>
      <el-table-column label="备注" align="center"  key= "company" prop="remark" v-if = "columns[17].visible" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="borrowYuliu1" align="center"  key= "borrowYuliu1" prop="borrowYuliu1" v-if = "columns[18].visible" :show-overflow-tooltip="true"/>-->
<!--      <el-table-column label="borrowYuliu2" align="center"  key= "borrowYuliu2" prop="borrowYuliu2" v-if = "columns[19].visible" :show-overflow-tooltip="true"/>-->
<!--      <el-table-column label="borrowYuliu3" align="center"  key= "borrowYuliu3" prop="borrowYuliu3" v-if = "columns[20].visible" :show-overflow-tooltip="true"/>-->
<!--      <el-table-column label="borrowYuliu4" align="center"  key= "borrowYuliu4" prop="borrowYuliu4" v-if = "columns[21].visible" :show-overflow-tooltip="true"/>-->
      <el-table-column label="借出状态" align="center" key= "borrowflag" prop="borrowflag"  v-if = "columns[1].visible" :show-overflow-tooltip="true">
        <template slot-scope="scope">
<!--          <span>{{ getFormattedBorrowFlag(scope.row.borrowflag) }}</span>-->
          <dict-tag :options="dict.type.borrow_dict" :value="scope.row.borrowflag"/>
        </template>
      </el-table-column>
      <el-table-column label="归还状态" align="center"  key= "returnflag" prop="returnflag" v-if = "columns[12].visible" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.borrow_still" :value="scope.row.returnflag"/>
<!--          <span>{{ getFormattedReturnFlag(scope.row.returnflag) }}</span>-->
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 借阅管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal='false'>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
<!--        <el-form-item label="借出标志" prop="borrowflag" >-->
<!--          <el-select v-model="form.borrowflag" placeholder="请输入借出标志" disabled>-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.borrow_dict"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="id" prop="id">-->
<!--          <el-input v-model="form.id" placeholder="请输入id"  />-->
<!--        </el-form-item>-->
        <el-form-item label="借出文件类型" prop="filetype">
          <el-input v-model="form.filetype" placeholder="请输入借出文件类型" />
        </el-form-item>
        <el-form-item label="借阅人" prop="name">
          <el-input v-model="form.name" placeholder="借阅人" />
        </el-form-item>
        <el-form-item label="单位名称" prop="company">
          <el-input v-model="form.company" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="证件号码" prop="paperno">
          <el-input v-model="form.paperno" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="联系电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="公司地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入公司地址" />
        </el-form-item>
        <el-form-item label="借出原因" prop="reason">
          <el-input v-model="form.reason" placeholder="请输入借出原因" />
        </el-form-item>
        <el-form-item label="介绍信" prop="recommendation">
          <el-input v-model="form.recommendation" placeholder="请输入介绍信" />
        </el-form-item>
        <el-form-item label="借出时间" prop="borrowtime">
          <el-date-picker clearable
            v-model="form.borrowtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择借出时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="借出经办人" prop="borrowoperator">
          <el-input v-model="form.borrowoperator" placeholder="请输入借出经办人" />
        </el-form-item>
        <el-form-item label="借出期限" prop="loantime">
          <el-input v-model="form.loantime" placeholder="请输入借出期限" />
        </el-form-item>
        <el-form-item label="到期时间" prop="duetime">
          <el-date-picker clearable
            v-model="form.duetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择到期时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="归还时间" prop="returntime">
          <el-date-picker clearable
            v-model="form.returntime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择归还时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="归还经办人" prop="returnoperator">
          <el-input v-model="form.returnoperator" placeholder="请输入归还经办人" />
        </el-form-item>
        <el-form-item label="归还标志" prop="returnflag">
          <el-input v-model="form.returnflag" placeholder="请输入归还标志" />
        </el-form-item>-->
        <el-form-item label="申请时间" prop="applytime">
          <el-date-picker clearable
            v-model="form.applytime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审批人" prop="approvaloperator">
          <el-input v-model="form.approvaloperator" placeholder="请输入审批人" />
        </el-form-item>
        <el-form-item label="审批时间" prop="approvaltime">
          <el-date-picker clearable
            v-model="form.approvaltime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工程名称" prop="engname">
          <el-input v-model="form.engname" placeholder="请输入工程名称" />
        </el-form-item>
        <el-form-item label="案卷题名" prop="vname">
          <el-input v-model="form.vname" placeholder="请输入案卷题名" />
        </el-form-item>
        <el-form-item label="文件题名" prop="filename">
          <el-input v-model="form.filename" placeholder="请输入文件题名" />
        </el-form-item>
<!--        <el-form-item label="用户id" prop="userId">-->
<!--          <el-input v-model="form.userId" placeholder="请输入用户id" />-->
<!--        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
<!--        <el-form-item label="状态值标志" prop="statusflag">-->
<!--          <el-select v-model="form.statusflag"   disabled>-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.borrow_audit"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预留字段1" prop="borrowYuliu1">
          <el-input v-model="form.borrowYuliu1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="borrowYuliu2">
          <el-input v-model="form.borrowYuliu2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="borrowYuliu3">
          <el-input v-model="form.borrowYuliu3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="borrowYuliu4">
          <el-input v-model="form.borrowYuliu4" placeholder="请输入预留字段4" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">添加</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 归还管理对话框 -->
    <el-dialog :title="title" :visible.sync="open_lend" width="600px" append-to-body :close-on-click-modal='false'>
      <el-form ref="form_lend" :model="form_lend" :rules="rules_lend" label-width="110px">
        <el-form-item label="id" prop="id">
          <el-input v-model="form_lend.id" placeholder="请输入id" disabled />
        </el-form-item>
        <el-form-item label="借阅人" prop="name">
          <el-input v-model="form_lend.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="归还时间" prop="returntime">
          <el-date-picker clearable
                          v-model="form_lend.returntime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择归还时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="归还经办人" prop="returnoperator">
          <el-input v-model="form_lend.returnoperator" placeholder="请输入归还经办人" />
        </el-form-item>
<!--        <el-form-item label="归还标志" prop="returnflag">-->
<!--&lt;!&ndash;          <el-input v-model="form_lend.returnflag" placeholder="请输入归还标志"  />&ndash;&gt;-->
<!--          <el-select v-model="form_lend.returnflag" placeholder="请输入归还标志"  disabled>-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.borrow_still"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form_lend.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">修改</el-button>
        <el-button @click="cancel_lend">取 消</el-button>
      </div>
    </el-dialog>
      <div v-if = "selectedRow" class = "detail-info">
      <h3>详细信息</h3>
        <div class="info-row">
          <div class="info-column">
            <p>id：{{selectedRow.id}}</p>
        <p>文件类型：{{selectedRow.filetype}}</p>
        <p>借出标志：{{getFormattedBorrowFlag(selectedRow.borrowflag)}}</p>
        <p>借阅人：{{selectedRow.name}}</p>
        <p>单位名称：{{selectedRow.company}}</p>
        <p>证件号码：{{selectedRow.paperno}}</p>
        <p>联系电话：{{selectedRow.telephone}}</p>
        <p>公司地址：{{selectedRow.address}}</p>
        <p>借出原因：{{selectedRow.reason}}</p>
        <p>介绍信：{{selectedRow.recommendation}}</p>
        <p>借出时间：{{selectedRow.borrowtime}}</p>
        <p>借出经办人：{{selectedRow.borrowoperator}}</p>
            <p>借出期限：{{selectedRow.loantime}}</p>

          </div>
          <div class="info-column">
        <p>到期时间：{{selectedRow.duetime}}</p>
        <p>归还时间：{{selectedRow.returntime}}</p>
        <p>归还经办人：{{selectedRow.returnoperator}}</p>
        <p>归还标志：{{getFormattedReturnFlag(selectedRow.returnflag)}}</p>
        <p>申请时间：{{selectedRow.applytime}}</p>
        <p>审批人：{{selectedRow.approvaloperator}}</p>
        <p>审批时间：{{selectedRow.approvaltime}}</p>
        <p>工程名称：{{selectedRow.engname}}</p>
        <p>案卷题名：{{selectedRow.vname}}</p>
        <p>文件题名：{{selectedRow.filename}}</p>
        <p>用户ID：{{selectedRow.userId}}</p>
        <p>备注：{{selectedRow.remark}}</p>

<!--            <p>状态值：{{getFormattedStatusFlag(selectedRow.statusflag)}}</p>-->
          </div>
        </div>
      </div>
  </div>
</template>

<script>
import { listBorrow, getBorrow, delBorrow, addBorrow, updateBorrow } from "@/api/system/borrow";
import '@/assets/styles/borrow.css';
import {getUserProfile} from "@/api/system/user";
export default {
  name: "Borrow",
  dicts: [ 'borrow_dict','borrow_still','borrow_audit'],
  data() {
    return {
      userId:null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 借阅管理表格数据
      borrowList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      open_lend: false,
      //借出返回
      borrowDict: [],
      //归还返回
      returnDict: [],
      //状态值返回
      statusDict:[],
      //数据展示
      selectedRow:null,
      // 查询参数
      queryParams: {
        id:null,
        pageNum: 1,
        pageSize: 10,
        filetype: null,
        borrowflag: null,
        name: null,
        company: null,
        paperno: null,
        telephone: null,
        address: null,
        reason: null,
        recommendation: null,
        borrowtime: null,
        borrowoperator: null,
        loantime: null,
        duetime: null,
        returntime: null,
        returnoperator: null,
        returnflag: null,
        applytime: null,
        approvaloperator: null,
        approvaltime: null,
        engname: null,
        vname: null,
        filename: null,
        userId: null,
        borrowYuliu1: null,
        borrowYuliu2: null,
        borrowYuliu3: null,
        borrowYuliu4: null,
        // statusflag:null,
      },
      // 表单参数
      form: {},
      // 表单参数
      form_lend: {},
      // 列信息
      columns: [
        { key: 0, label: `文件类型`, visible: true },
        { key: 1, label: `借出标志`, visible: true },
        { key: 2, label: `姓名`, visible: true},
        { key: 3, label: `单位名称`, visible: false },
        { key: 4, label: `证件号码`, visible: false },
        { key: 5, label: `联系电话`, visible: false },
        { key: 6, label: `公司地址`, visible: false },
        { key: 7, label: `借出原因`, visible: false },
        { key: 8, label: `介绍信`, visible: false },
        { key: 9, label: `借出经办人`, visible: false },
        { key: 10, label: `借出期限`, visible: false },
        { key: 11, label: `归还经办人`, visible: false },
        { key: 12, label: `归还标志`, visible: true },
        { key: 13, label: `审批人`, visible: true },
        { key: 14, label: `工程名称`, visible: false },
        { key: 15, label: `文件题名`, visible: true },
        { key: 16, label: `用户id`, visible: false },
        { key: 17, label: `备注`, visible: false },
        { key: 18, label: `borrowYuliu1`, visible: false },
        { key: 19, label: `borrowYuliu2`, visible: false },
        { key: 20, label: `borrowYuliu3`, visible: false },
        { key: 21, label: `borrowYuliu4`, visible: false },
        { key: 22, label: `案卷题名`, visible: true },
        { key: 23, label: '状态值' , visible: true},
        { key: 24, label: '审批时间' , visible: false},
        { key: 25, label: 'id' , visible: true}
      ],
      // 表单校验
      rules: {
        name:[
          {required:true,message:"借阅人不能为空",trigger: "blur"},
          { min: 2, max: 20, message: '姓名长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        approvaloperator:[
          {required:true,message:"审批人名称不能为空",trigger: "blur"},
          { min: 2, max: 20, message: '审批人名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        telephone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        // id: [
        //   {required:true,message:"id不能为空，不能与已有id重复",trigger: "blur"},
        // ]
      },

      rules_lend: {
        returnoperator:[
          {required:true,message:"归还经办人名称不能为空",trigger: "blur"},
          { min: 2, max: 20, message: '归还经办人名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        name:[
          {required:true,message:"用户名称不能为空",trigger: "blur"},
          { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
      },
    };
  },
  /** 0 1 数据转换为字*/
  computed: {
    formattedBorrowFlag() {
      return this.borrowDict.reduce((acc, dict) => {
        acc[dict.value] = dict.label;
        return acc;
      }, {});
    },
    formattedReturnFlag() {
      return this.returnDict.reduce((acc, dict) => {
        acc[dict.value] = dict.label;
        return acc;
      }, {});
    },
    formattedStatusFlag() {
      return this.statusDict.reduce((acc, dict) => {
        acc[dict.value] = dict.label;
        return acc;
      }, {});
    },
  },
  created() {
    this.getProfile()
    this.getDictData();
    this.getList();
  },
  methods: {
    getProfile(){
      getUserProfile().then(res =>{
        this.userId = res.data.userId
        // console.log(res)
      })
    },
    /** 查询借阅管理列表 */
    getList() {
      this.loading = true;
      listBorrow(this.queryParams).then(response => {
        this.borrowList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    cancel_lend() {
      this.open_lend = false;
      this.reset_lend();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        filetype: null,
        borrowflag: null,
        name: null,
        company: null,
        paperno: null,
        telephone: null,
        address: null,
        reason: null,
        recommendation: null,
        borrowtime: null,
        borrowoperator: null,
        loantime: null,
        duetime: null,
        returntime: null,
        returnoperator: null,
        returnflag: null,
        applytime: null,
        approvaloperator: null,
        approvaltime: null,
        engname: null,
        vname: null,
        filename: null,
        userId: null,
        remark: null,
        borrowYuliu1: null,
        borrowYuliu2: null,
        borrowYuliu3: null,
        borrowYuliu4: null,
        // statusflag:null
      };
      this.resetForm("form");
    },

    // 表单重置
    reset_lend() {
      this.form_lend = {
        id: null,
        filetype: null,
        name: null,
        returntime: null,
        returnoperator: null,
        returnflag: null,
        // statusflag:null,

      };
      this.resetForm("form_lend");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.selectedRow = null;

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增借阅信息";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset_lend();
      const id = row.id || this.ids
      var query = {};
      query.id = id[0];
      listBorrow(query).then(response =>{
        this.form_lend = response.rows[0];
        this.open_lend = true;
        this.title = "新增归还信息";
      })
      // getBorrow(id).then(response => {
      //   this.form_lend = response.data;
      //   this.open_lend = true;
      //   this.title = "新增归还信息";
      // });
    },

    /** 归还按钮 */
    submitForm() {
      this.form_lend.borrowflag = 0
      this.form_lend.returnflag = 1
      // this.form_lend.statusflag = 0
      this.$refs["form_lend"].validate(valid => {
        if (valid) {
          updateBorrow(this.form_lend).then(response => {
            this.$modal.msgSuccess("归还成功");
            this.selectedRow = null;
            this.open_lend = false;
            this.getList();
          })
            .catch(error => {
              // 处理修改失败的情况
              this.$message.error("归还失败：" + error.message);
            });
        } else {
          // 表单验证未通过，可以根据需要进行处理
          this.$message.warning("请填写正确的表单数据");
        }
      });
    },
    /** 提交借阅按钮 */
    submitForm1() {
      this.form.borrowflag = 3
      this.form.returnflag = 2
      this.form.userId = this.userId
      // this.form.statusflag = 0
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          addBorrow(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
            this.selectedRow = null;
          })
            .catch(error => {
              // 处理新增失败的情况
              this.$message.error("新增失败：" + error.message);
            });
        } else {
          // 表单验证未通过，可以根据需要进行处理
          this.$message.warning("请填写正确的表单数据");
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      var query = {};
      if(this.ids.length === 0){
        query.id = row.id;
        this.$modal.confirm('是否确认删除借阅管理编号为"' + query.id + '"的数据项？').then(function () {
          return delBorrow(query);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
          this.selectedRow = null;
        }).catch(() => {
        });
      }
      else {
        query.ids = this.ids;
        this.$modal.confirm('是否确认删除借阅管理编号为"' + query.ids + '"的数据项？').then(function () {
          return delBorrow(query);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
          this.selectedRow = null;
        }).catch(() => {
        });
      }

    },

    // 获取格式化后的借阅标志
    getFormattedBorrowFlag(value) {
      return this.formattedBorrowFlag[value] || "";
    },
    // 获取格式化后的归还标志
    getFormattedReturnFlag(value) {
      return this.formattedReturnFlag[value] || "";
    },
    //获取格式化后的状态值标志
    getFormattedStatusFlag(value) {
      return this.formattedStatusFlag[value] || "";
    },
    // 获取字典数据
    getDictData() {
      this.borrowDict = [
        {value: 0, label: '未借出'},
        {value: 1, label: '已借出'}
      ];
      this.returnDict = [
        {value: 0, label: '未归还'},
        {value: 1, label: '已归还'}
      ];
      this.statusDict = [
        {value:0, label: '待审核'},
        {value:1, label: '已通过'},
        {value:2, label: '已驳回'}
      ];
    },
    handleRowClick(row) {
      this.selectedRow = row;
    },

  }
};
</script>

<style>
.info-row {
  border: 1px solid #ccc; /* 添加边框样式 */
  padding: 10px; /* 添加一些内边距 */
}
.info-column p:not(:last-child) {
  border-bottom: 1px solid #ddd; /* 添加底部边框 */
  padding-bottom: 5px; /* 为每个 <p> 元素添加一些底部内边距 */
}
</style>
